package org.meow.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.meow.dto.UserPageDTO;
import org.meow.dto.UserRegisterDTO;
import org.meow.entity.User;
import org.meow.result.Result;
import org.meow.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * &#064;Date: 24/05/14-16:56
 * &#064;Description:
 */
@RestController
@RequestMapping("/admin")
@Tag(name = "管理员接口")
public class UserMgrController {
  @Autowired
  private UserService userService;

  @PostMapping("/user")
  @Operation(summary = "查询用户列表")
  public Result<IPage<User>> getUserList(@RequestBody UserPageDTO userPageDTO) {
    IPage<User> pageResult = userService.pageQuery(userPageDTO);
    return Result.success(pageResult);
  }

  @PostMapping("/user/register")
  @Operation(summary = "用户注册")
  public Result<String> register(@RequestBody UserRegisterDTO userRegisterDTO) {
    userService.insert(userRegisterDTO);
    return Result.success();
  }

  @PutMapping("/user/status/{status}")
  @Operation(summary = "更新用户状态")
  public Result<String> updateStatus(@PathVariable Integer status, @RequestParam Long id) {
    userService.updateStatus(status, id);
    return Result.success();
  }

}
